import { _decorator, Vec3 , Node, randomRangeInt} from 'cc';
import { SkillManager } from './SkillManager';
import { EGroup, EntityType, ESkill, ESkillType } from '../Config/Enum';
import ObjectPoolManager from '../Core/ObjectPoolManager';
import { Collider2D } from 'cc';
import { PlayerManager } from '../PlayerManager';
import { WudangBo } from './WudangBo';
import { EnemyManager } from '../EnemyManager';

const { ccclass } = _decorator;
// rune1: "其他武学减调息时间0.5秒",
// rune2: "额外造成敌人当前生命值5%的伤害",
// rune3: "巨剑掠过战场，造成额外500%伤害",
@ccclass('WudangSkill2')
export class WudangSkill2 extends SkillManager {
    private _hasSplit = false;
    runeId = 0
    numOfBullets = 3; // 默认是3个
    level

    // 新增标志：是否是主子弹（由玩家直接发射的子弹）
    private isMasterBullet = true;


    init(type: ESkill, pm: PlayerManager) {
        // 如果是子子弹，就不要拿numOfBullets了,直接super.init(type, pm);直接释放
        if (!this.isMasterBullet) {
            super.init(type, pm);
            return;
        }

        // 如果是主子弹，就拿numOfBullets，并判断runeId，走逻辑，再释放
        if (this.isMasterBullet) {
            this._hasSplit = false;
        }

        //this.numOfBullets = pm.skills.get(type).numOfBullets +  pm.skills.get(type).level; // 获取当前武学的符文ID

        //this.reset();
        super.init(type, pm);
        this.direction = new Vec3(200,200,0)

        console.log("符文WudangSkill2 init runeId", this.runeId);
        
        // 其他符文效果
        switch (this.runeId) {
            
            case 1:
                for(const skill of this.pm.skills.values()){
                    skill.cd -= 0.1
                    // 如果小于0，则等于0
                    if(skill.cd < 0){
                        skill.cd = 0
                    }
                    console.log("武当符文1效果，其他武学减调息时间0.1秒", skill.type, skill.cd);
                }
                break;
            case 2:
                // 穿透效果在碰撞处理中实现
                this.effectChance = 0.2
                break;  
            case 3:
                if(Math.random()<0.5){

                }
                break;
            default:
                //console.log("WudangSkill1 no rune", this.runeId);
                break;
        }

    }

    protected onHitEnemy(self, other: Collider2D): void {
        this.em = other.node.getComponent(EnemyManager)

        switch (this.runeId) {
            case 1:
                break;
            case 2:
                // 穿透效果在碰撞处理中实现
                this.damage += this.em.hp*0.05
                break;  
            case 3:
                if(this.em.hp < this.em.maxHp*0.3){
                    this.isCritical = true
                }      
                break;
            default:
                //console.log("WudangSkill1 no rune", this.runeId);
                break;
        }

        super.onHitEnemy(self, other,this.isCritical);
    }

            // 先调用父类方法处理伤害
            









}